package com.jams.goodox.adapter;

import android.support.v4.content.ContextCompat;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jams.goodox.R;
import com.jams.goodox.entity.Address;

import java.util.List;

/**
 * Created by Jin on 2016/5/19.
 * Description
 */
public class MineAddressAdapter extends BaseQuickAdapter<Address> {

    private boolean notControl;// true 为不需要控制
    private boolean isComeFromMineFragment;
    public MineAddressAdapter(List<Address> list,boolean isComeFromMineFragment,boolean notControl) {
        super(R.layout.mine_address_listview, list);
        this.isComeFromMineFragment = isComeFromMineFragment;
        this.notControl = notControl;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, Address resultListBean) {
        if (null != resultListBean) {
            baseViewHolder.setText(R.id.name, resultListBean.getName())
                    .setText(R.id.phonenum, resultListBean.getPhone())
                    .setText(R.id.address, resultListBean.getAreaAddress() +"\n"+ resultListBean.getAddressDetail())
                    .setOnClickListener(R.id.mine_address_edit_btn, new OnItemChildClickListener())
                    .setOnClickListener(R.id.rl1, new OnItemChildClickListener())
                    .setVisible(R.id.mine_address_edit_btn, !resultListBean.isCommunity())
                    .setVisible(R.id.tx_is_default,getViewHolderPosition(baseViewHolder)==0);


            baseViewHolder.getView(R.id.check).setVisibility(!isComeFromMineFragment && resultListBean.getIsCommunity() == 1 ? View.VISIBLE : View.GONE);

            if (!resultListBean.isInServiceArea() && !notControl) {
                baseViewHolder.setTextColor(R.id.name, ContextCompat.getColor(mContext, R.color.font_color_gray))
                        .setTextColor(R.id.phonenum, ContextCompat.getColor(mContext, R.color.font_color_gray))
                        .setTextColor(R.id.address, ContextCompat.getColor(mContext, R.color.font_color_gray));
            } else {
                baseViewHolder.setTextColor(R.id.name, ContextCompat.getColor(mContext, R.color.font_color_black))
                        .setTextColor(R.id.phonenum, ContextCompat.getColor(mContext, R.color.font_color_black))
                        .setTextColor(R.id.address, ContextCompat.getColor(mContext, R.color.font_color_deep_gray));
            }

            baseViewHolder.setVisible(R.id.kx, resultListBean.isCommunity());
            baseViewHolder.setVisible(R.id.kx_bottom, resultListBean.isCommunity());
        }
    }
}
